<?php session_start() ?>
<!DOCTYPE html>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
   <title>留言记录</title>
   <link href="../css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<?php require '../public/header.php'?>
<!-- 导航栏 -->
<ul class="nav nav-pills">
   <li><a href="home.php">主页</a></li>
   <li class="active"><a href="#">留言记录</a></li>
   <li><a href="friends.php">我的好友</a></li>
   <li ><a href="add_friends.php">添加好友</a></li>
   <li><a href="notice.php">我的消息</a></li>
</ul>
<hr/>
<div class="panel panel-info"> 	
	<div class="panel-heading" id="message_record">
     	<h3 class="panel-title">我收到的</h3>
   </div>
	<div class="panel-body">
		<?php
		if(isset($_SESSION['username'])){
			require('../public/conn.php');//连接数据库
			$username = $_SESSION['username'];
			$query="SELECT * FROM messages WHERE send_to='$username' AND 	                     belong_to = '1' ORDER BY time_stamp DESC";
			$result = mysql_query($query);
			$count = mysql_num_rows($result);//得到留言条数
			$hasMessage = false;//标志是否有留言
			while($row = mysql_fetch_array($result)){
				echo "<hr/>";
	  			echo "<a href='#'>".$row['send_from']."</a>";
	  			echo "&nbsp;&nbsp;".date('Y-m-d H:i:s',$row['time_stamp'])."                     <br>" ;
	  			echo "".$row['message']."<br/><br/>";
				echo "<p style='color:999999'>".$count."楼</p>";
				$count--;
				$hasMessage = true;	
			}
			if(!$hasMessage){
 				echo "<h4>暂无留言记录</h4>";
			}
			mysql_close($con);
		}else{
			echo "亲,先去<a href='../face/login-face.php'><span>登陆</span>                </a>吧！";
		}
		 ?>
   </div>
</div>
<div class="panel panel-info"> 	
	<div class="panel-heading" id="message_record">
     	<h3 class="panel-title">我发送的</h3>
   </div>
	<div class="panel-body">
		<?php
		if(isset($_SESSION['username'])){
			require('../public/conn.php');//连接数据库
			$username = $_SESSION['username'];
			$query="SELECT * FROM messages WHERE send_from='$username' ORDER BY time_stamp DESC";
			$result = mysql_query($query);
			$count = mysql_num_rows($result);//得到留言条数
			$hasMessage = false;//标志是否有留言
			while($row = mysql_fetch_array($result)){
				echo "<hr/>";
	  			echo "接收者:<a href='#'>".$row['send_to']."</a>";
	  			echo "&nbsp;&nbsp;".date('Y-m-d H:i:s',$row['time_stamp'])."                     <br>" ;
	  			echo "".$row['message']."<br/><br/>";
				echo "<p style='color:999999'>".$count."楼</p>";
				$count--;
				$hasMessage = true;	
			}
			if(!$hasMessage){
 				echo "<h4>你还没有给任何人留言额！,快去<a href='friends.php'>留言</a>吧.....</h4>";
			}
		}else{
			echo "亲,先去<a href='../face/login-face.php'><span>登陆</span>                </a>吧！";
		}
		 ?>
   </div>
</div>
<?php require('../public/footer.php');?>
</body>
</html>